{extend name="public/base" /}

{block name="main"}

<el-row :gutter="20">
    <el-col :span="12" :offset="6">

        <el-form ref="form" :model="formd" label-width="120px"  size="small">
            <el-form-item label="KEY">
                <el-input v-model="formd.key"></el-input>
            </el-form-item>
            <el-form-item label="值类型">
                <el-select v-model="formd.value_type" placeholder="请选择值类型">
                    {foreach $vts as $key=>$vo }
                    <el-option label="{$vo}" value="{$key}"></el-option>
                    {/foreach}
                </el-select>
            </el-form-item>
            <el-form-item label="VALUE ">
                <el-input type="textarea"  rows="10" v-model="formd.value"  maxlength="5000"    show-word-limit></el-input>
            </el-form-item>

            {foreach $dimensionList as $item }
            <el-form-item label="{$item['title']}">
                <el-input v-show="{$item['if_free']}==1"  v-model="formd.{$item['key']}"></el-input>
                <el-select v-show="{$item['if_free']}!=1" v-model="formd.{$item['key']}" placeholder="请选择值">
                    {foreach $item["values_array"] as $vo }
                    <el-option label="{$vo}" value="{$vo}"></el-option>
                    {/foreach}
                </el-select>
            </el-form-item>
            {/foreach}


            <el-form-item label="备注">
                <el-input type="textarea" v-model="formd.rem"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">创建</el-button>

            </el-form-item>
        </el-form>

    </el-col>
</el-row>

{include file="public/config_rem"  /}

{/block}

{block name="js"}

<script>


    var keys= {:json_encode($keys)};
    var config={"value_type":"string"};



</script>
<script>
    new Vue({
        el: '#app',
        data: {
            formd: config
        },

        methods: {
            onSubmit() {
                console.log(this.formd);
                var vm = this;
                if(!vm.formd.key){
                    alert("key is not null!");
                    return ;
                }
                if(!vm.formd.value_type){
                    alert("值类型不能为空!");
                    return ;
                }
                axios
                    .post('/index/api/insertConfig',vm.formd )
                    .then(function (response) {
                        if(confirm("创建成功！测试一下？")){
                            window.location="/valuetest?"+ getSelectString(vm.formd,keys) ;
                        }
                        else{
                            location.reload();
                        }
                    });

            }
        },
    })
</script>

{/block}